package io.zhiller.ollamaclient.di.viewmodel

import androidx.lifecycle.ViewModel
import io.zhiller.ollamaclient.di.state.AppState
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update

class AppVM : ViewModel() {
  private val _state = MutableStateFlow(AppState())
  val state: StateFlow<AppState> = _state
  
  /**
   * 更新 apiUrl
   * @param newUrl 新的 URL
   */
  fun updateApiUrl(newUrl: String) = _state.update { currentState ->
    currentState.copy(apiUrl = newUrl)
  }
}